#include <iostream>
#include <map>
#include <cmath>
using namespace std;

bool IsPrime(int N)
{
    for (int index = 2; index<(int)(pow(N, 0.5)+ 1); index++)
    {
        if (N % index == 0)
        {
            return false;
        }
    }
    return true;
}

void FindingNearestPrimeNum(int Num)
{
    int NearestPrimeNumber = 0;
    int BiggerNearestPrimeNumber = 0;
    int SmallerNearestPrimeNumber = 0;
    
    for (int NumIndex = Num; NumIndex*10000; NumIndex++)
    {
        if ((NumIndex > Num) && (IsPrime(NumIndex)))
        {
            BiggerNearestPrimeNumber = NumIndex;
            break;
        }
    }
    for (int NumIndex = Num; 10000; NumIndex--)
    {
        if ((NumIndex < Num) && (IsPrime(NumIndex)))
        {
            SmallerNearestPrimeNumber = NumIndex;
            break;
        }
    }
    if (BiggerNearestPrimeNumber - Num < Num - SmallerNearestPrimeNumber)
    {
        cout << BiggerNearestPrimeNumber << endl;
    }
    else
    {
        cout << SmallerNearestPrimeNumber << endl;        
    }
}

int main() 
{
    string StringNum;
    string WordNumber = "";
    string DigitNumber = "";
    
    map <string, string> Digits = {
        {"zero","0"},
        {"one","1"},
        {"two","2"},
        {"three","3"},
        {"four","4"},
        {"five","5"},
        {"six","6"},
        {"seven","7"},
        {"eight","8"},
        {"nine","9"}
    };
    
    getline(cin, StringNum);
    
    int index = 0;
    while (index < (int)StringNum.size()) 
    {
        while (StringNum[index] == ' ')
        {
            index ++; 
        }
        WordNumber = "";
        while (index < (int)StringNum.size() and StringNum[index] != ' ')
        {
            WordNumber = WordNumber  + StringNum[index];
            index ++;
            DigitNumber = DigitNumber + Digits[WordNumber];
        }

    }
    if (stoi(DigitNumber) / 10 < 10)
    {
        cout << "WRONG INPUT" << endl;
    }
    else
    {
        FindingNearestPrimeNum(stoi(DigitNumber));
    }
}





